package ac.technion.gcchat.messages;

import ac.technion.gcframework.serialization.IObjectSerializationAgent;
import ac.technion.gcframework.serialization.SerializationUtils;

/**
 * Generated on Fri Jul 22 15:43:13 IDT 2011
 */
public class NewStreamMessageSerializationAgent implements IObjectSerializationAgent
{
	public void serialize(Object obj, byte[] buf, int loc)
	{
		NewStreamMessage typedObj = (NewStreamMessage)obj;
		int fieldSize;

		fieldSize = SerializationUtils.getStringSerializationSize(typedObj.getFileName());
		SerializationUtils.serialize(typedObj.getFileName(), buf, loc);
		loc += fieldSize;
		fieldSize = SerializationUtils.getLongSerializationSize(typedObj.getLengthInKb());
		SerializationUtils.serialize(typedObj.getLengthInKb(), buf, loc);
		loc += fieldSize;
		fieldSize = SerializationUtils.getLongSerializationSize(typedObj.getLengthInSeconds());
		SerializationUtils.serialize(typedObj.getLengthInSeconds(), buf, loc);
		loc += fieldSize;
	}

	public Object deSerialize(byte[] buf, int loc)
	{
		NewStreamMessage obj = new NewStreamMessage();
		int size=0;
		size = SerializationUtils.getSerializedStringSize(buf, loc);
		obj.setFileName(SerializationUtils.deSerializeString(buf, loc));
		loc += size;
		size = SerializationUtils.getSerializedLongSize(buf, loc);
		obj.setLengthInKb(SerializationUtils.deSerializeLong(buf, loc));
		loc += size;
		size = SerializationUtils.getSerializedLongSize(buf, loc);
		obj.setLengthInSeconds(SerializationUtils.deSerializeLong(buf, loc));
		loc += size;
		return obj;
	}

	public int getSerializationSize(Object obj)
	{
		NewStreamMessage typedObj = (NewStreamMessage)obj;

		int size=0;
		size += SerializationUtils.getStringSerializationSize(typedObj.getFileName());
		size += SerializationUtils.getLongSerializationSize(typedObj.getLengthInKb());
		size += SerializationUtils.getLongSerializationSize(typedObj.getLengthInSeconds());
		return size;
	}

	public int getSerializedSize(byte[] buf, int loc)
	{
		int totalSize = 0;
		int fieldSize;

		fieldSize = SerializationUtils.getSerializedStringSize(buf, loc);
		totalSize += fieldSize;
		loc += fieldSize;

		fieldSize = SerializationUtils.getSerializedLongSize(buf, loc);
		totalSize += fieldSize;
		loc += fieldSize;

		fieldSize = SerializationUtils.getSerializedLongSize(buf, loc);
		totalSize += fieldSize;
		loc += fieldSize;

		return totalSize;
	}
}